package com.example.mscloud.controller;

import com.example.mscloud.common.entities.Payment;
import com.example.mscloud.common.entities.result.CommonResult;
import com.example.mscloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class PaymentController
{
    @Value("${server.port}")
    private int port;

    @Resource
    private PaymentService payMentService;

    @PostMapping("payment/create")
    public CommonResult create(@RequestBody Payment payMent){
        int result = payMentService.create(payMent);
        if (result > 0)
            return new CommonResult(200, "success", result);
        else
            return new CommonResult(444, "failer");
    }

    @GetMapping("payment/info/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id){
        Payment payMent = payMentService.getById(id);
        return new CommonResult(200, "success", payMent);
    }

    @GetMapping("payment/heartbeat")
    public CommonResult heartbeat(){

        return new CommonResult(200, "success", "server port: " + port);
    }


}
